<template>
    <div class="cmt-container">
        <h3>发表评论</h3>
        <hr>
        <textarea placeholder="请输入输入内容,最多120字 " maxlength="120"></textarea>
        <mt-button type="primary" size="large">提交</mt-button>
        <div class="cmt-list">
            <div class="cmt-item" v-for="item in comment">
                <div class="cmt-title">{{item.floor}}&nbsp;&nbsp;用户:匿名用户&nbsp;&nbsp;发表时间:{{item.time}}</div>
                <div class="cmt-body">{{item.title}}</div>
            </div>
        </div>
        <mt-button type="danger" size="large" plain>加载更多</mt-button>
    </div>
</template>

<script>
    export default {
        data(){
            return {
                comment:[]
            }

        },
        created(){
            this.getComment();
        },
        methods:{

            getComment(){
                var sendData={id:this.id};
                this.$http.jsonp('http://localhost:80/vue-cms/3.php/comment',{params :sendData})
                    .then(data=>{
                        if(data.status === 200){
                            //console.log(data)
                            this.comment = JSON.parse(data.bodyText);
                            //注意这个返回的值仍然是一个字符串，这样子就会导致其实返回不了正确的结果，需要用JSON.parse对其进行一次处理，这样子就可以得到
                            //正确的JSON格式的字符串
                            console.log(this.comment);
                        }else {
                            Toast("加载数据失败")
                        }
                    })
            }
        },
        props:['id']
    }
</script>

<style scoped>
    .cmt-container h3{
        font-size:18px;
    }
    .cmt-container textarea{
        font-size: 14px;
        height: 85px;
        margin: 0;
    }
    .cmt-container .cmt-list{
        margin:10px 0
    }
    .cmt-container .cmt-list .cmt-item{
        font-size:13px;

    }
    .cmt-container .cmt-list .cmt-item .cmt-title{
        line-height: 30px;
        background-color: #ccc;
    }
    .cmt-container .cmt-list .cmt-item .cmt-body{
        line-height: 35px;
        text-indent: 2em
    ;
    }
</style>